#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,l,m,s,d[100005],p[100005],v[100005],t,a[100005],c;
int f=0,fl=0;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        ll ans=0;
        cin>>n>>m>>l>>s;
        for(ll i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(ll i=1;i<=m;i++){
            cin>>p[i];
        }
        for(ll i=1;i<=n;i++){
            if(a[i]>=0||v[i]>s){
                c=d[i]+(pow(s,2)-pow(v[i],2))/(2*a[i]);
                if(c>=d[i]&&c<=l){
                    if(a[i]>=0){
                        if(p[m]>=c){
                            ans++;
                            f=1;
                        }
                    }
                    else{
                        ll cs=lower_bound(p[1],p[m],d[i])-cs;
                        if(cs<=c){
                            ans++;
                            fl=1;
                        }
                    }
                }
            }
        }
        cout<<ans<<" "<<f+fl<<endl;
    }
}
